# -*- coding:utf-8 -*-

import FileUtils



#版本号控制脚本
class VersionHelper:
    def __init__(self, path):
        self.path = path        
        self.versionStr = FileUtils.readFileData(path)
        print("self.versionStr = ",self.versionStr)
        self.initAllSingleVersion()

    def initAllSingleVersion(self):
        _versionList = self.versionStr.split(".")
        self.bigVersion = int(_versionList[0])
        self.midVersion = int(_versionList[1])
        self.smallVersion = int(_versionList[2])
        print("self.bigVersion",self.bigVersion)
        print("self.midVersion",self.midVersion)
        print("self.smallVersion",self.smallVersion)


    def getBigVersion(self):
        return self.bigVersion
    def getMidVersion(self):
        return self.midVersion
    def getSmallVersion(self):
        return self.smallVersion
    def getVersionStr(self):
        return self.versionStr


    def addBigVersion(self):
        self.bigVersion = self.bigVersion + 1 
        self.updateVersion()
    def addMidVersion(self):
        self.midVersion = self.midVersion + 1 
        self.updateVersion()
    def addSmallVersion(self):
        self.smallVersion = self.smallVersion + 1 
        self.updateVersion()

    def updateVersion(self):
        self.versionStr = str(self.bigVersion) + "." + str(self.midVersion) + "." + str(self.smallVersion)
        FileUtils.writeToFile(self.path,self.versionStr)

    def resetVersion(self):
        self.versionStr = "1.0.0"
        self.initAllSingleVersion()

    def saveVersion(self,filePath):
        FileUtils.writeToFile2(filePath,self.versionStr)